export default class WxCanvas {
  constructor(ctx, canvasId, isNew, canvasNode) {
    this.ctx = ctx;
    this.canvasId = canvasId;
    this.chart = null;
    this.isNew = isNew
    if (isNew) {
      this.canvasNode = canvasNode;
    }
  }

  setChart(chart) {
    this.chart = chart;
  }

  attachEvent() {
    // noop
  }

  detachEvent() {
    // noop
  }

  prepare() {
    if (this.isNew) {
      this.ctx.save();
      return;
    }

    this.ctx.save();
    const pixelRatio = this.chart.getDevicePixelRatio();
    this.ctx.scale(pixelRatio, pixelRatio);
  }

  getContext(contextType) {
    if (contextType === '2d') {
      return this.ctx;
    }
  }

  setPixelRatio(pixelRatio) {
    this.pixelRatio = pixelRatio;
  }

  createImage() {
    if (this.isNew) {
      const image = this.canvasNode.createImage();
      return image;
    }
    return wx.createImage();
  }

  attendTouch() {
    // noop
  }

  unattendTouch() {
    // noop
  }

  measureText(text) {
    return this.ctx.measureText(text);
  }
} 